package com.app.mingluxing.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.app.mingluxing.R;
import com.app.mingluxing.bean.Child;
import com.app.mingluxing.utils.CommonUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Aaron on 2015/7/21.
 */
public class ChooseOneAdapter extends BaseAdapter {

    private Context ctx;

    private List<Child> peoples;
//
//    private SharedPreferences sp;
//    private String currentChildId;

    public ChooseOneAdapter(Context ctx, List<Child> peoples) {
        this.ctx = ctx;
        this.peoples = peoples;
//        //获得sp的值
//        sp = ctx.getSharedPreferences(Constant.CONFIG, ctx.MODE_PRIVATE);
    }

    public void setData(List<Child> peoples) {
        this.peoples = peoples;
    }

    @Override
    public int getCount() {
        return peoples.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;

        if (convertView == null) {

//            convertView = View.inflate(ctx, R.layout.item_baby, null);
//            viewHolder = new ViewHolder();
//            viewHolder.iv_receiver_pic = (ImageView) convertView.findViewById(R.id.iv_receiver_pic);
//            viewHolder.iv_is_select = (ImageView) convertView.findViewById(R.id.iv_is_select);
//            viewHolder.tv_receiver_name = (TextView) convertView.findViewById(R.id.tv_receiver_name);
//            convertView.setTag(viewHolder);
            convertView = View.inflate(ctx, R.layout.item_home_choose_baby, null);
            viewHolder = new ViewHolder();
            viewHolder.iv_receiver_pic = (ImageView) convertView.findViewById(R.id.iv_receiver_pic);
            viewHolder.rl_child = (RelativeLayout) convertView.findViewById(R.id.rl_child);
            viewHolder.tv_receiver_name = (TextView) convertView.findViewById(R.id.tv_receiver_name);
            viewHolder.tv_watch_tel = (TextView) convertView.findViewById(R.id.tv_watch_tel);
            viewHolder.tv_attention_people = (TextView) convertView.findViewById(R.id.tv_attention_people);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.rl_child.setSelected(peoples.get(position).isSelect);
        viewHolder.tv_receiver_name.setText(CommonUtils.isNull(peoples.get(position).name) ? "" : peoples.get(position).name);
        viewHolder.tv_watch_tel.setText(CommonUtils.isNull(peoples.get(position).device.phoneNum) ? "" : peoples.get(position).device.phoneNum);
        viewHolder.tv_attention_people.setText(CommonUtils.isNull(peoples.get(position).birthday) ? "" : peoples.get(position).birthday);

        if (!CommonUtils.isNull(peoples.get(position).picUrl)) {
            ImageLoader.getInstance().displayImage(peoples.get(position).picUrl, viewHolder.iv_receiver_pic);
        }

        return convertView;
    }


//    private class ViewHolder {
//
//        private ImageView iv_receiver_pic;
//        private ImageView iv_is_select;
//        private TextView tv_receiver_name;
//
//    }

    private class ViewHolder {

        private ImageView iv_receiver_pic;
        private RelativeLayout rl_child;
        private TextView tv_receiver_name;
        private TextView tv_watch_tel;
        private TextView tv_attention_people;

    }

}
